// pages/operation/classRecord/evaluateDetails/index.js
import { ClassModel } from "../../../../api/api-work/classModel.js"
const classModel = new ClassModel()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    id: "",
    form: {},
    classDate: "",
    classRoomName: "",
    description: "",
    assistantName: "",
    firstTabTitle: "已评价(0)",
    firstPageNum: 1,
    firstTotal: 0,
    firstTableData: [],
    firstTriggered: false,
    firstLoadStatus: "",
    secondTabTitle: "未评价(0)",
    secondPageNum: 1,
    secondTotal: 0,
    secondTableData: [],
    secondTriggered: false,
    secondLoadStatus: ""
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    this.setData({
      id: options.id
    })
    this.getClassTimeById()
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {
    this.setData({
      firstTriggered: false,
      firstPageNum: 1,
      firstTableData: [],
      secondTriggered: false,
      secondPageNum: 1,
      secondTableData: []
    })
    // 获取已评价学员
    this.getEvaluateList()
    // 获取未评价学员
    this.getNotEvaluateList()
  },

  // 获取详情
  getClassTimeById() {
    classModel.getClassTimeByIdApi({ id: this.data.id }).then(res => {
      this.setData({
        form: res,
        classDate: res.classDate && res.classDate.split(" ")[0],
        classRoomName: res.classRoomName == null ? "-" : res.classRoomName,
        description: res.description == null ? '-' : res.description,
        assistantName: res.assistantName == null ? '-' : res.assistantName
      })
      // 获取已评价学员
      this.getEvaluateList()
      // 获取未评价学员
      this.getNotEvaluateList()
    })
  },

  // 获取评价列表
  getEvaluateList() {
    classModel.getEvaluateListApi({ pageNum: this.data.firstPageNum, pageSize: 15, state: 0, orderNo: this.data.form.orderNo }).then(res => {
      let rows = this.data.firstTableData;
      rows.push(...res.rows);
      this.setData({
        firstTableData: rows,
        firstTotal: res.total,
        firstTabTitle: '已评价(' + res.total + ")"
      })
      if (this.data.firstTotal == 0) {
        this.setData({
          firstLoadStatus: ""
        })
      } else if (this.data.firstTableData.length < this.data.firstTotal) {
        this.setData({
          firstLoadStatus: "loadmore"
        })
      } else {
        this.setData({
          firstLoadStatus: "nomore"
        })
      }
    })
  },
  getMoreFirstDatas() {
    if (this.data.firstLoadStatus === "nomore") {
      return;
    }
    this.setData({
      firstPageNum: this.data.firstPageNum + 1,
      firstLoadStatus: "loading"
    })
    this.getEvaluateList()
  },
  refreshMoreFirstDatas() {
    this.setData({
      firstTriggered: false,
      firstPageNum: 1,
      firstTableData: []
    })
    this.getEvaluateList()
  },
  // 获取未评价列表
  getNotEvaluateList() {
    classModel.getEvaluateListApi({ pageNum: this.data.secondPageNum, pageSize: 15, state: 1, orderNo: this.data.form.orderNo }).then(res => {
      let rows = this.data.secondTableData;
      rows.push(...res.rows);
      this.setData({
        secondTableData: rows,
        secondTotal: res.total,
        secondTabTitle: '未评价(' + res.total + ")"
      })
      if (this.data.secondTotal == 0) {
        this.setData({
          secondLoadStatus: ""
        })
      } else if (this.data.secondTableData.length < this.data.secondTotal) {
        this.setData({
          secondLoadStatus: "loadmore"
        })
      } else {
        this.setData({
          secondLoadStatus: "nomore"
        })
      }
    })
  },
  getMoreSecondDatas() {
    if (this.data.secondLoadStatus === "nomore") {
      return;
    }
    this.setData({
      secondPageNum: this.data.secondPageNum + 1,
      secondLoadStatus: "loading"
    })
    this.getNotEvaluateList()
  },
  refreshMoreNotDatas() {
    this.setData({
      secondTriggered: false,
      secondPageNum: 1,
      secondTableData: []
    })
    this.getNotEvaluateList()
  },

  // 评价详情
  navigateToDetails(e) {
    let obj = { ...e.currentTarget.dataset.query, className: this.data.form.className, classDate: this.data.classDate, classStartTime: this.data.form.classStartTime, classEndTime: this.data.form.classEndTime, teacherName: this.data.form.teacherName, courseNameC: this.data.form.courseNameC }
    const param = JSON.stringify(obj);

    wx.navigateTo({
      url: `/pages/operation/classRecord/evaluateStudentDetails/index?param=${param}`,
    })
  },
  // 去评价
  navigateToEvaluateStudent(e) {
    let obj = { ...e.currentTarget.dataset.query, className: this.data.form.className, classDate: this.data.classDate, classStartTime: this.data.form.classStartTime, classEndTime: this.data.form.classEndTime, teacherName: this.data.form.teacherName, courseNameC: this.data.form.courseNameC }
    const param = JSON.stringify(obj);

    wx.navigateTo({
      url: `/pages/operation/classRecord/evaluateStudent/index?param=${param}`,
    })
  },
  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})